package torres.item;

import java.util.List;

import torres.action.Action;
import torres.entity.Entity;
import torres.fileIO.BasicContainer;
import torres.fileIO.ClassContainer;

/**
 * @author Torres
 * Represents an Equippable Item. Includes all the 
 * information necessary to modify the equipee's stats
 */

public class EquippableItem extends TakeableItem
{
	private int offensiveMod;
	private int armorMod;
	
	public EquipType equipType;
	
	/**
	 * Creates a new EquippableItem with the specified name.
	 * @param name Name (and image name) of the item.
	 * @param id ID of EquippableItem
	 * @param itemCost Value of TakeableItem
	 */
	public EquippableItem(String name, int id, int itemCost) {
		super(name, id, itemCost);
		offensiveMod = 0;
		armorMod = 0;
		equipType = EquipType.HEAD;
	}
	
	/**
	 * Creates a new EquippableItem with the specified effects.
	 * @param name Name (and image name) of the item.
	 * @param effects The effects that occur when equipping the item.
	 * @param itemCost Value of TakeableItem
	 */
	public EquippableItem(String name, int id, List<Action> effects, int itemCost) {
		super(name, id, effects, itemCost);
		offensiveMod = 0;
		armorMod = 0;
		equipType = EquipType.HEAD;
		//imageName = "dekuShield.png";
	}
	
	/**
	 * Creates a new EquippableItem with the specified stats.
	 * @param name Name (and image name) of the item.
	 * @param offMod The offensive modifier of the item.
	 * @param armMod The armor modifier of the item.
	 * @param equipType The kind of equipment this is: Head, Upper, Lower, Left, Right
	 * @param itemCost Value of TakeableItem
	 */
	public EquippableItem(String name, int id, int offMod, int armMod, EquipType equipType, int itemCost) {
		super(name, id, itemCost);
		this.setOffensiveMod(offMod);
		this.setArmorMod(armMod);
		this.equipType = equipType;
	}
	
	/**
	 * Creates a new EquippableItem which is a copy of the specified item.
	 * @param item The item to be copied. 
	 */
	public EquippableItem(EquippableItem item) {
		this(item.getName(), item.getID(), item.getOffensiveMod(), item.getArmorMod(), item.getType(), item.getItemCost());
	}
	
	
	/**
	 * Returns the offensive modifier of the item.
	 * @return The offensive modifier of the item. 
	 */
	public int getOffensiveMod() {
		
		return offensiveMod;
	}
	
	/**
	 * Returns the armor modifier of the item.
	 * @return The armor modifier of the item. 
	 */
	public int getArmorMod() {
		
		return armorMod;
	}
	
	/**
	 * Set the offensive modifier of this item to the specified value.
	 * @param offensiveMod  Value of the new offensive modifier.
	 */
	private void setOffensiveMod(int offensiveMod) {
		
		this.offensiveMod = offensiveMod;
	}
	
	/**
	 * Set the offensive modifier of this item to the specified value.
	 * @param offensiveMod  Value of the new offensive modifier.
	 */
	private void setArmorMod(int armorMod) {
		
		this.armorMod = armorMod;
	}
	
	/** Returns the enum Type of the item: Head, Upper, Lower, Left, Right
	 * @return The kind of equipment
	 */
	public EquipType getType()
	{
		return equipType;
	}
	
	/* (non-Javadoc)
	 * @see torres.item.TakeableItem#getToolTip()
	 */
	public String getToolTip() {
		String ret="<html>Name: " + super.getName()+"<br>";
		ret += "Equip type: "+equipType+"<br>";
		ret += "Offensive Mod: "+offensiveMod+"<br>";
		ret += "Armor Mod: "+armorMod+"<br>";
		ret += "</html>";
		return ret;
	}

	/* (non-Javadoc)
	 * @see torres.item.TakeableItem#save()
	 */
	@Override
	public ClassContainer save() {
		ClassContainer curClass = super.save();
		curClass.addProperty(new BasicContainer("type", "EquippableItem"));
		return curClass;
	}

	/* (non-Javadoc)
	 * @see torres.item.TakeableItem#use(torres.entity.Entity)
	 */
	public void use(Entity e) {
		e.equipItem(this);
	}
	

	/*@Override
=======
	/* (non-Javadoc)
	 * @see torres.item.TakeableItem#load(torres.fileIO.ClassContainer)
	 */
	@Override
	public void load(ClassContainer classContainer) {
		super.load(classContainer);
		BasicContainer offensiveModCont = (BasicContainer)classContainer.getProperty("offensiveMod");
		offensiveMod = (Integer)offensiveModCont.getValue();
		BasicContainer armorModCont = (BasicContainer)classContainer.getProperty("armorMod");
		armorMod = (Integer)armorModCont.getValue();
		BasicContainer equipTypeCont = (BasicContainer)classContainer.getProperty("equipType");
		equipType = (EquipType)equipTypeCont.getValue();	
	}

	public boolean addToEquipInventory(EquippedInventory equipInventory) {
		return equipInventory.addItem(this);
	}

	public void removeFromEquipInventory(EquippedInventory equipInventory) {
		equipInventory.removeItem(this);
	}
	
}
